package com.glut.campusrepair.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.glut.campusrepair.dto.AddEvaluationdto;
import com.glut.campusrepair.dto.MaintenanceShortRecordsdto;
import com.glut.campusrepair.dto.ShowEvaluationdto;
import com.glut.campusrepair.entity.ServiceEvaluation;
import com.glut.campusrepair.mapper.ServiceEvaluationMapper;
import com.glut.campusrepair.service.IServiceEvaluationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户评分表 服务实现类
 *
 * @author sanminzhi
 * @since 2024-07-19 11:26
 */
@Service
public class ServiceEvaluationServiceImpl extends ServiceImpl<ServiceEvaluationMapper, ServiceEvaluation> implements IServiceEvaluationService {

    @Autowired
    ServiceEvaluationMapper serviceEvaluationMapper;

    /**wsy
     * 通过维修记录id给维修记录添加评价
     *点击评价按钮后的操作
     * */
    @Override
    public boolean save(AddEvaluationdto addEvaluationdto) {
        int count = serviceEvaluationMapper.insert_2(addEvaluationdto);
        return count == 1;
    }

    /**wsy
     * 通过用户id查询所有简洁版的维修记录，再通过其中的维修记录id查找出相应的评价
     *点击查看评价按钮后的操作
     * */
    @Override
    public List<MaintenanceShortRecordsdto> selectAssociation(Integer userNo) {
        return serviceEvaluationMapper.selectAssociation(userNo);
    }

    /**wsy
     * 点击提交评价按钮后，根据维修记录id将评价状态（eva_status）的值改为’已评价‘
     * */
    @Override
    public boolean updateEvaStatus(Integer maintenanceRecordsId) {
        int num = serviceEvaluationMapper.updateEvaStatus(maintenanceRecordsId);
        return (num == 1) ;
    }

    /**wsy
     * 点击查看评价按钮后，根据维修记录id查询出相应的评价信息
     * */
    @Override
    public ShowEvaluationdto selectEvaluationById(Integer maintenanceRecordsId) {
        return serviceEvaluationMapper.selectEvaluationById(maintenanceRecordsId);
    }
}
